/**
 * 
 */
package com.ofek.eventos.db;

import java.io.Serializable;

import android.content.Context;

import com.ofek.base.db.DataField;
import com.ofek.base.db.DataTypeClass;
import com.ofek.eventos.db.datatypes.predefined.PageDefiner;
import com.ofek.eventos.util.IOUtils;

/**
 * @author Ofek
 *
 */
@DataTypeClass
public class PageWrapper implements PageDefiner {
	@DataField(isKey=true,isAutoIncrement=true)
	public long id;
	@DataField
	public String serial;
	private PageDefiner pDef;
	/**
	 * 
	 */
	public PageWrapper() {
	}
	public PageWrapper(final Serializable serial) {
		this.serial = IOUtils.objectToString(serial);
	}
	/**
	 * 
	 */
	private void init() {
		pDef = IOUtils.stringToObject(serial, PageDefiner.class);
	}
	@Override
	public String getStartsWith() {
		if (pDef==null) init();
		return pDef.getStartsWith();
	}
	@Override
	public String getPageTitle(final Context pageActivity) {
		if (pDef==null) init();
		return pDef.getPageTitle(pageActivity);
	}
	@Override
	public long getStart() {
		if (pDef==null) init();
		return pDef.getStart();
	}
	@Override
	public String getPageSubTitle(final Context pageActivity) {
		if (pDef==null) init();
		return pDef.getPageSubTitle(pageActivity);
	}
	@Override
	public long getEnd() {
		if (pDef==null) init();
		return pDef.getEnd();
	}
	@Override
	public Long getTypeId() {
		if (pDef==null) init();
		return pDef.getTypeId();
	}
	@Override
	public Long getDefaultTypeId() {
		if (pDef==null) init();
		return pDef.getDefaultTypeId();
	}
	@Override
	public boolean careForTime() {
		if (pDef==null) init();
		return pDef.careForTime();
	}
	@Override
	public String getOwner() {
		if (pDef==null) init();
		return pDef.getOwner();
	}
	/**
	 * @return
	 */
	public PageDefiner getPageDefiner() {
		if (pDef==null) init();
		return pDef;
	}
	public ContextWrapper getParent() {
		return ContextDatabase.getInstance().getParent(this);

	}

}
